<template>
	<view>
		<hx-navbar ref="hxnb" :config="config">
			<block slot="right">
				<view class="edit" @tap="editName()">
					保存
				</view>
			</block>
		</hx-navbar>
		<view class="name">
			<input type="text" :placeholder="placeholderName" v-model="userName">
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 标题栏配置
				config: {
					title: "",
					back: true,
					color: "#111111",
					rightSlot: true,
					backgroundColor: [1, "#FFFFFF"],
				},
				placeholderName: '',
				userName: '',
				index: '',
				groupNum: '',
				id: ''
			}
		},
		onLoad(e) {
			if (e.index == 1) {
				this.config.title = "项目名称"
				this.placeholderName = e.groupName
				this.groupNum = e.groupNum
			} else {
				this.config.title = "我的名字"
				this.placeholderName = e.myName
				this.groupNum = e.groupNum
				this.id = e.id
			}
			this.index = e.index
			console.log('姓名', e)
		},
		methods: {
			editName() {
				if (this.index == 1) {
					let data = {
						name: this.userName,
						groupNum: this.groupNum
					}
					this.$api.projectName(data).then((res) => {
						if (this.$cache.get('type') != 1) return this.$tools.showToast('只有群主才能修改群名字')
						if (res.statusCode == 200) {
							uni.navigateBack(1)
						}
					})
				} else if (this.index == 2) {
					let data = {
						name: this.userName,
						groupNum: this.groupNum,
						id: this.id
					}
					this.$api.chatName(data).then((res) => {
						this.$cache.set('name', this.userName)
						console.log('笨蛋额', res)
						if (res.statusCode == 200) {
							uni.navigateBack(1)
						}
					})
				}

			}
		}
	}
</script>

<style scoped>
	input::input-placeholder {
		color: rgba(30, 30, 30, 0.2);
	}

	.edit {
		width: 162rpx;
		height: 70rpx;
		border-radius: 10rpx;
		text-align: center;
		line-height: 70rpx;
		font-size: 32rpx;
		color: #009BFF;
	}

	.name {
		margin-top: 30rpx;
		padding: 30rpx;
		background-color: #fff;
	}
</style>